home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / graphic / boxleft.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  6.4 KB  |  243 lines

  1. ;void box_left(box,col,row,width,depth);
  2. ;  unsigned char  *box,*col,*row,width,depth;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _video_buffer:word
  6.     EXTRN  _snow_protect:byte
  7.  
  8. box_seg EQU  [bp-2]
  9. box_ofs EQU  [bp-4]
  10. col_seg EQU  [bp-6]
  11. col_ofs EQU  [bp-8]
  12. row_seg EQU  [bp-10]
  13. row_ofs EQU  [bp-12]        
  14. width    EQU  [bp-14]        
  15. depth   EQU  [bp-16]        
  16. snow    EQU  [bp-18]        
  17. endofbox EQU  [bp-20]    
  18. toppos  EQU  [bp-22]        
  19. rghtpos EQU  [bp-24]        
  20.  
  21. _TEXT    SEGMENT  BYTE PUBLIC 'CODE'
  22.     ASSUME CS:_TEXT
  23.     PUBLIC _box_left
  24. _box_left proc near
  25.     push bp            ;
  26.     mov  bp,sp        ;set stack frame
  27.     sub  sp,24        ;make room to hold parameters
  28.     pushf            ;
  29.     push di            ;
  30.     push si            ;
  31.     cmp  _memory_model,0    ;near or far?
  32.     jle  begin        ;jump if near
  33.     inc  bp            ;else add 2 to BP
  34.     inc  bp            ;
  35. begin:    push ds            ;save Turbo's DS
  36.     mov  dx,_video_buffer    ;grab _video_buffer
  37.     push dx            ;save it
  38.     cmp  _memory_model,2    ;data near or far?
  39.     jb   L0            ;jump if near
  40.     push [bp+6]        ;move parameters to SP offsets
  41.     push [bp+10]
  42.     push [bp+14]
  43.     push [bp+4]
  44.     push [bp+8]
  45.     push [bp+12]
  46.     push [bp+16]
  47.     push [bp+18]
  48.     jmp  short L00
  49. L0:    push ds            ;near case
  50.     push ds
  51.     push ds
  52.     push [bp+4]
  53.     push [bp+6]
  54.     push [bp+8]
  55.     mov  al,[bp+10]
  56.     sub  ah,ah
  57.     push ax
  58.     mov  al,[bp+12]
  59.     push ax
  60. L00:    cmp  _memory_model,0    ;check code model again
  61.     jle  L000        ;jump if near
  62.     dec  bp            ;unadjust BP so all BP offsets same
  63.     dec  bp            ;
  64. L000:    pop  depth        ;set intermediate values
  65.     pop  width
  66.     pop  row_ofs
  67.     pop  col_ofs
  68.     pop  box_ofs
  69.     pop  row_seg
  70.     pop  col_seg
  71.     pop  box_seg
  72.     mov  ax,col_seg        ;ES:DI pts to Col
  73.     mov  es,ax        ;
  74.     mov  di,col_ofs        ;
  75.     mov  al,_snow_protect    ;grab _snow_protect
  76.     mov  snow,al        ;save it
  77.     sub  cx,cx        ;
  78.     mov  cl,es:[di]        ;get column position
  79.     jcxz J1            ;quit if column is zero
  80.     dec  cx            ;count from zero
  81.     cmp  cx,79        ;in range?
  82.     jna  I1            ;jump ahead if so
  83.     jmp  T1            ;else quit
  84. I1:    cmp  cx,2        ;not on left edge?
  85.     jnb  K1            ;jump ahead if not
  86. J1:    jmp  T1            ;else quit routine
  87. K1:    dec  cx            ;old col minus 2
  88.     mov  es:[di],cl        ;change the setting
  89.     inc  cx            ;restore old col pos
  90.     mov  ax,box_seg        ;segment of Box
  91.     mov  es,ax        ;load in ES
  92.     mov  di,box_ofs        ;offset of Box
  93.     mov  ax,depth        ;depth to AX
  94.     dec  ax            ;dec for test
  95.     cmp  ax,24        ;in range?
  96.     jna  L1            ;jump ahead if so
  97.     jmp  T1            ;else quit routine
  98. L1:    inc  ax            ;readjust
  99.     mov  bx,width        ;width to BX
  100.     dec  bx            ;dec for test
  101.     cmp  bx,79        ;in range?
  102.     jna  M1            ;jump ahead if so
  103.     jmp  T1            ;else quit
  104. M1:    inc  bx            ;readjust
  105.     mul  bl            ;width times depth
  106.     shl  ax,1        ;double for attributes
  107.     add  ax,di        ;offset to end of Box
  108.     mov  endofbox,ax    ;save end of box ptr
  109.     mov  di,ax        ;pt ES:DI to end of Box
  110.     mov  ax,row_seg        ;DS:SI pts to Row
  111.     mov  ds,ax        ;
  112.     mov  si,row_ofs        ;
  113.     sub  ax,ax        ;
  114.     mov  al,[si]        ;get row value
  115.     dec  ax            ;count from zero
  116.     cmp  ax,24        ;in range?
  117.     jna  N1            ;jump ahead if so
  118.     jmp  T1            ;else quit
  119. N1:    mov  bl,160        ;bytes per row
  120.     mul  bl            ;calculate row offset
  121.     shl  cx,1        ;col offset
  122.     add  ax,cx        ;add to row offset
  123.     mov  si,ax        ;SI pts to topleft corner
  124.     mov  toppos,si        ;save it
  125.     mov  ax,dx        ;_video_buffer
  126.     mov  ds,ax        ;move to DS
  127.     mov  ax,width        ;width
  128.     shl  ax,1        ;double for attributes
  129.     add  si,ax        ;DS:SI pts to topright
  130.     mov  rghtpos,si        ;copy position
  131.     pop  bx            ;_video_buffer
  132.     cld            ;set direction
  133.     mov  si,toppos        ;point to topleft corner
  134.     sub  si,4        ;minus two columns
  135.     mov  cx,depth        ;depth
  136.     mov  dx,si        ;DX holds start col
  137. O1:    mov  si,dx        ;set start col
  138.     call Writeit        ;write a char
  139.     call Writeit        ;write another
  140.     add  dx,160        ;forward one row
  141.     loop O1            ;do next row
  142.     mov  ax,ds        ;DS to AX
  143.     mov  es,ax        ;now ES pts to screen too
  144.     mov  si,toppos        ;top left position
  145.     mov  di,si        ;copy to DI
  146.     sub  di,4        ;will shift right by 2
  147.     mov  dx,depth        ;depth
  148.     mov  ax,width        ;width
  149. P1:    mov  cx,ax        ;width to CX
  150.     push di            ;save target start
  151.     push si            ;save source start
  152. Q1:    call Writeit        ;write a char
  153.     loop Q1            ;go do next
  154.     pop  si            ;restore source start
  155.     pop  di            ;restore target start
  156.     add  di,160        ;forward dest ptr
  157.     add  si,160        ;forward source ptr
  158.     dec  dx            ;dec row counter
  159.     jnz  P1            ;loop till image shifted
  160.     mov  ax,box_seg        ;segment of Box
  161.     mov  ds,ax        ;move to DS
  162.     mov  si,box_ofs        ;offset of Box
  163.     mov  di,rghtpos        ;ES:DI pts to old topleft
  164.     sub  di,4        ;leftwards by 2 cols
  165.     mov  cx,depth        ;depth
  166.     mov  dx,width        ;width
  167.     sub  dx,2        ;minus 2 for 2 columns
  168.     shl  dx,1        ;double for attributes
  169. R1:    add  si,dx        ;forward Box ptr
  170.     call Writeit        ;write a char
  171.     call Writeit        ;write another
  172.     add  di,156        ;forward target ptr
  173.     loop R1            ;do next row
  174.     std            ;reverse direction flag
  175.     mov  ax,ds        ;DS pts to Box
  176.     mov  es,ax        ;now ES does too
  177.     mov  di,endofbox    ;offset to end of Box
  178.     dec  di            ;dec screen ptr
  179.     dec  di            ;again
  180.     mov  si,di        ;copy to SI
  181.     sub  si,4        ;source pos 2 chars left
  182.     mov  ax,depth        ;depth
  183.     mov  cx,width        ;width
  184.     mul  cl            ;size of Box
  185.     mov  cx,ax        ;move to CX as counter
  186.     rep  movsw        ;shift all downwards
  187.     mov  di,box_ofs        ;offset of Box
  188.     mov  si,endofbox    ;offset of Col
  189.     mov  cx,depth        ;depth
  190.     cld            ;direction flag forward
  191. S1:    movsw            ;move first word of two
  192.     movsw            ;move the next
  193.     add  di,dx        ;forward target ptr
  194.     loop S1            ;go move 2 more chars
  195.     jmp  short U1        ;jump to end
  196. T1:    pop  bx            ;balance stack if error
  197. U1:    sti            ;reenable interrupts
  198.     pop  ds            ;
  199.     pop  si            ;
  200.     pop  di            ;
  201.     popf            ;
  202.     add  sp,24        ;restore stack pointer
  203.     pop  bp            ;
  204.     cmp  _memory_model,0    ;quit
  205.     jle  quit        ;
  206.     db   0CBh        ;RET far
  207. quit:    ret            ;RET near
  208. _box_left endp
  209. Writeit    PROC
  210.     push dx            ;save DX
  211.     push ax            ;save AX too
  212.     mov  dx,es        ;get target segment
  213.     mov  ax,ds        ;get source segment
  214.     cmp  ax,dx        ;is source larger?
  215.     jna  A1            ;jump if not
  216.     mov  dx,ax        ;else use source
  217. A1:    cmp  byte ptr snow,0    ;protect against snow?
  218.     je   F1            ;jump ahead if not
  219.     mov  dx,3dah        ;status byte address
  220. B1:    in   al,dx        ;get status byte
  221.     test al,1        ;test bit
  222.     jnz  B1            ;loop till 0        
  223.     cli            ;disable interrupts
  224. C1:    in   al,dx        ;get status byte
  225.     test al,1        ;test bit
  226.     jz   C1            ;loop till 1
  227.     movsb            ;write a char
  228. D1:    in   al,dx        ;get status byte
  229.     test al,1        ;test bit
  230.     jnz  D1            ;loop till 0
  231. E1:    in   al,dx        ;get status byte
  232.     test al,1        ;test bit
  233.     jz   E1            ;loop till 1        
  234.     movsb            ;write a char
  235.     jmp  short G1        ;jump ahead and quit
  236. F1:    movsw            ;move the character
  237. G1:    pop  ax            ;restore AX
  238.     pop  dx            ;restore DX
  239.     ret            ;
  240. Writeit    endp
  241. _TEXT    ENDS
  242.     END
  243.